import {fhirSearchApi, fhirHistoryApi, fhirDeleteApi} from "../../api/modules/fhirApi";
import {createProcedureApi, searchProcedureApi, updateProcedureApi} from "../../api/modules/procedureApi";

export default {
  state: {
    procedures: []
  },
  mutations: {
    setProcedures(state, data) {
      state.procedures = data;
    }
  },
  actions: {
    getProcedureList({commit, rootState}, params) {
      return searchProcedureApi(params).then(res => {
        commit('setProcedures', res.data.entry ? res.data.entry : [{resource: res.data}])
      }).catch(res => {
        commit('setProcedures', []);
      })
    },
    getHistoryProcedureList({commit, rootState}, params) {
      return fhirHistoryApi(params).then(res => {
        commit('setProcedures', res.data.entry ? res.data.entry : [{resource: res.data}])
      })
    },
    updateProcedure({commit, rootState}, params) {
      return updateProcedureApi(params);
    },
    createProcedure({commit, rootState}, params) {
      return createProcedureApi(params);
    },
    deleteProcedure({commit, rootState}, params) {
      return fhirDeleteApi(params);
    }
  }
}
